<?php

 /*  
         * ======================================================================================
         * 
         * ALL the Zend_Forms classes performed by Jean Carlo Machado has the following scope:
         * 
         * public function init(); 
         * public function showForm($name,$destinationUrl);
         * 
         * The first one serves only to zend authenticate the fom         * 
         * The second one serves to show the form without use Zend patters
         * of forms. 
         * 
         * =======================================================================================
         * To call on the controllers or helpers scope:
         * 
         *      To show:
         *              require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                        $form = new Forms_CriarNodo();
                        $form->setAction($this->_helper->url('recivecreatenod'));
                        $form->showForm('create','/nodo/recivecreatenod');
         * 
         *      To pick back (IN THE ACTION PASSED TO SHOW FORM):
         *                  require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                            $form = new Forms_CriarNodo();

                            if($this->getRequest()->isPost())
                            {
                                $data = $this->_request->getPost();

                                print_r($data);

                                if($form->isValid($data))
                                {
                                   //DO SOMETHING
                                }
                                else
                                {
                                     $this->view->message = 'Dados Invalidos';
                                }
         * =========================================================================================
         * 
         */
class Forms_CadastrarUsuario extends Zend_Form 
{
    
    public function init()
    {
        /* The elements are the following :
         * name (text)
         * lastName (text)
         */
        $this->setMethod("POST");
        
        $action = new Zend_Form_Element_Hidden('action','cadastrarUser');
        
        $name = $this->createElement('text','name',null);
        $name->setRequired(TRUE);
             //->addValidator('alnum');
        
        $lastName = $this->createElement('text','lastName',null);
        $lastName->setRequired(TRUE);
                // ->addValidator('alnum');
        
        $eMail = $this->createElement('text','eMail',null);
        $eMail->setRequired(TRUE);
        
        $passwd = new Zend_Form_Element_Password('password');
        $passwd->setRequired(TRUE);
        
        $this->addElement($name);
        $this->addElement($lastName);
        $this->addElement($eMail);
        $this->addElement($passwd);
        $this->addElement('submit','go',NULL);
    }
    
    public function showForm($name,$destinationUrl)
    {
        $return = "";        
        $return.= "<form name='$name' method='POST' action='$destinationUrl'>";
        $return.= "<input type='hidden' name='action' value='cadastrarUser'>";
        $return.= "Nome: <input type='text' name='name' value=''><br>";
        $return.= "Sobrenome: <input type='text' name='lastName' value=''><br>";
        $return.= "e-mail: <input type='text' name='eMail' value=''><br>";
        $return.= "Senha: <input type='password' name='password' value=''><br>";
        $return.= "<input type='submit' name='go' value='Enviar'>";
        $return.= "</form>";
        
        echo $return;
        
    }
}

?>
